package reflect1;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class<?> clazz = Class.forName("reflect1.Stu");
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field);
        }
        Field name = clazz.getDeclaredField("name");
        System.out.println(name);

        int modifiers = name.getModifiers();
        System.out.println(modifiers);

        System.out.println(name.getName());

        System.out.println(name.getType());

        Stu stu = new Stu("idufhs");
        name.setAccessible(true);
        System.out.println(name.get(stu));

        name.set(stu, "Lisa");
        System.out.println(stu);
    }
}
